<?php

class Core_Agent_Component_Filemanage_Controller_File extends Dcmp_Component_Controller {

    public function uploadAction(){
        $files = $this->getRequest()->getAllFiles();
        $dir = $this->getRequest()->getParameter('folder', NULL);
        if(is_null($dir)){
        	$dir = DP_TMP.'upload'.DS.Kd_Util_Random::randomNumeric();
        }else{
        	$dir = Kd_Web_Util::urlToPath($dir);
        }
        Kd_Util_IO::makeDirectory($dir);
        $fileUrls = array();
        foreach($files as $file){
        	$fileUrls[] = Kd_Web_Util::pathToUrl($file->saveRandom($dir));
        }
        return $this->jsonResult(array('success'=>1, 'fileUrls'=>$fileUrls));
    }
    
    public function deleteAction($fileurl){
    	$filePath = Kd_Web_Util::urlToPath($fileurl);
    	Kd_Util_IO::deleteFile($filePath);
    	return $this->jsonResult(array('success'=>1));
    }
}